import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.Closure;
import org.apache.commons.collections.CollectionUtils;


public class CollectionTest
{
	public static void main(String[] args)
	{
		testMapKey();
	}

	private static void testMapKey() {
		Map<String, String> map = new HashMap<String, String>();
		String keySsn = "PERSON.SSN";
		map.put(keySsn, "123");
		System.out.println("map: " + map);
		
		if (map.containsKey(keySsn)) {
			System.out.println("removing key " + keySsn);
			//map.remove(keySsn);
			map.remove(new String(keySsn));
			System.out.println("map: " + map);
		}
		
	}
	
	private static void test() {
		Set set = new HashSet();
		set.add("test");
		set.add(null);
		System.out.println("set: " + set);
		
		
		
		List list = new ArrayList();
		list.add(new StringBuffer("item1"));
		list.add(new StringBuffer("item2"));
		list.add(new StringBuffer("item3"));		
		System.out.println(list);
		
		CollectionUtils.forAllDo(list, new Closure() 
		{
			public void execute(Object input)
			{
				if (((StringBuffer) input).toString().equals("item2"))
				{
					((StringBuffer) input).append("_modified");
				}
			}
		});		
		System.out.println(list);
		
		for (Iterator iter = list.iterator(); iter.hasNext(); )
		{
			StringBuffer buf = (StringBuffer) iter.next();
			if (buf.toString().equals("item3"))
			{
				buf.append("_changed");
			}
		}
		System.out.println(list);

		StringBuffer buf1 = (StringBuffer) list.get(0);
		buf1.append("_updated");
		System.out.println(list);
		
		
		//testAddAll();
		
		List list1 = new ArrayList();
		list1.add("a");
		list1.add("b");
		Iterator iter = list1.iterator();
		while (iter.hasNext())
		{
			String item = (String) iter.next();
			System.out.println("item: " + item);
		}
		
		iter = list1.iterator();
		while (iter.hasNext())
		{
			String item = (String) iter.next();
			System.out.println("item: " + item);
		}
	}
	
	public static void testAddAll()
	{
		List list1 = new ArrayList();
		list1.add("a");
		list1.add("b");
		
		List list2 = new ArrayList();
		list2.add("a");
		list2.add("b");
		list2.add("c");		
		
		list1.addAll(list2);
		
		System.out.println("list1: " + list1);
	}

}
